package log

import (
	"github.com/magicianlyx/GoLog/graph"
)

var eobject = newGenerate(1000)

func initCode() {
	eobject.addError(ErrorServiceRpc)
	eobject.addError(ErrorServiceHttp)
	eobject.addError(ErrorApiNsq)
	eobject.addError(ErrorApiHttp)
	eobject.addError(ErrorApiWs)
	eobject.addError(ErrorApiRpc)
	eobject.addError(ErrorWxCallBack)
	eobject.addError(ErrorWxPay)
	eobject.addError(ErrorRequestAuthorize)
	eobject.addError(ErrorRequestNotAccess)
	eobject.addError(ErrorRequestParams)
	eobject.addError(ErrorDBMemCache)
	eobject.addError(ErrorDBMysql)
	eobject.addError(ErrorDBMongo)
	eobject.addError(ErrorDBRedis)
	eobject.addError(ErrorDBEs)
	eobject.addError(ErrorDataFormat)
	eobject.addError(ErrorDataSerialize)
	eobject.addError(ErrorDataConvert)
	eobject.addError(ErrorDataEncrypt)
	eobject.addError(ErrorDataStream)
	eobject.addError(ErrorDataFile)
	eobject.addError(ErrorDataCompression)
	eobject.addError(ErrorDataSignature)
	eobject.addError(ErrorDataInternal)
}

var (
	// 服务错误
	ErrorTypeService = graph.NewErrorType(nil, "Service", "服务错误")
	ErrorServiceRpc  = graph.NewError(ErrorTypeService, "service rpc error", "rpc服务错误")
	ErrorServiceHttp = graph.NewError(ErrorTypeService, "service http error", "http服务错误")
)

var (
	// 对外请求错误
	ErrorTypeApi = graph.NewErrorType(nil, "Network", "请求错误")
	ErrorApiNsq  = graph.NewError(ErrorTypeApi, "push nsq error", "推送nsq错误")
	ErrorApiHttp = graph.NewError(ErrorTypeApi, "request http error", "请求http错误")
	ErrorApiWs   = graph.NewError(ErrorTypeApi, "request websocket error", "请求websocket错误")
	ErrorApiRpc  = graph.NewError(ErrorTypeApi, "request rpc error", "请求rpc错误")
)

var (
	// 微信
	ErrorTypeWx     = graph.NewErrorType(nil, "WX", "请求微信接口错误")
	ErrorWxCallBack = graph.NewError(ErrorTypeWx, "callback payload error", "微信回调格式出错")
	ErrorWxPay      = graph.NewError(ErrorTypeBusiness, "wx pay error", "微信支付相关错误")
)

var (
	// 处理请求错误
	ErrorTypeReceiveRequest = graph.NewErrorType(nil, "Request", "接收请求错误")

	ErrorRequestAuthorize = graph.NewError(ErrorTypeReceiveRequest, "identity authorize error", "身份认证失败")
	ErrorRequestNotAccess = graph.NewError(ErrorTypeReceiveRequest, "identity not access error", "无权访问")
	ErrorRequestParams    = graph.NewError(ErrorTypeReceiveRequest, "request params error", "请求参数错误")
)

var (
	// 业务错误
	ErrorTypeBusiness = graph.NewErrorType(nil, "Business", "业务错误")
)

var (
	// 数据库操作错误
	ErrorTypeDB = graph.NewErrorType(nil, "DataBase", "数据库错误")

	ErrorDBMemCache = graph.NewError(ErrorTypeDB, "memory cache db error", "memcache数据错误")
	ErrorDBMysql    = graph.NewError(ErrorTypeDB, "mysql db error", "mysql数据库错误")
	ErrorDBMongo    = graph.NewError(ErrorTypeDB, "mongo db error", "mongo数据库错误")
	ErrorDBRedis    = graph.NewError(ErrorTypeDB, "redis error", "redis数据库错误")
	ErrorDBEs       = graph.NewError(ErrorTypeDB, "es error", "es数据库错误")
)

var (
	// 数据操作错误
	ErrorTypeData = graph.NewErrorType(nil, "Data", "数据错误")

	ErrorDataFormat      = graph.NewError(ErrorTypeData, "data format error", "数据格式错误")
	ErrorDataSerialize   = graph.NewError(ErrorTypeData, "data serialize error", "数据序列化错误")
	ErrorDataConvert     = graph.NewError(ErrorTypeData, "data convert error", "数据类型转换错误")
	ErrorDataEncrypt     = graph.NewError(ErrorTypeData, "data encrypt error", "数据加解密错误")
	ErrorDataStream      = graph.NewError(ErrorTypeData, "stream operate error", "流操作错误")
	ErrorDataFile        = graph.NewError(ErrorTypeData, "file system operate error", "文件系统错误")
	ErrorDataCompression = graph.NewError(ErrorTypeData, "file compression operate error", "文件加解压错误")
	ErrorDataSignature   = graph.NewError(ErrorTypeReceiveRequest, "check signature error", "签名检验失败")
	ErrorDataInternal    = graph.NewError(ErrorTypeData, "internal data error", "内部数据错误")
)
